
package com.ce.cases.source.action;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import com.ce.cases.check.dao.po.CaseCheckEnterprice;
import com.ce.cases.check.dao.po.CaseSourceCheck;
import com.ce.cases.execute.dao.po.CaseSourceExecute;
import com.ce.cases.hear.dao.po.CaseSourceHear;
import com.ce.cases.source.dao.po.CaseSource;
import com.ce.cases.source.dao.po.CaseSourceApprove;
import com.ce.cases.source.dao.po.CaseSourceDrawApprove;
import com.ce.cases.source.dao.po.CaseSourceFiles;
import com.ce.cases.source.dao.po.CaseSourceFilesTemplate;
import com.ce.framework.constants.WebConstants;
import com.ce.framework.context.FrameworkContext;
import com.ce.framework.datamaintain.action.DataMaintainAction;
import com.ce.framework.datamaintain.dao.po.AbstractPO;
import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.BeanAccessUtil;
import com.ce.framework.util.DateUtil;
import com.ce.framework.util.FileUtil;
import com.ce.framework.util.GeneratorUUID;
import com.ce.framework.util.LogUtil;
import com.ce.framework.util.StringUtil;
import com.ce.framework.util.node.JsonTreeNode;
import com.ce.pub.upload.dao.po.PubFileUploadLog;
import com.ce.sys.dict.dao.po.SysDictItem;
import com.ce.sys.login.model.User;
import com.ce.sys.org.dao.po.SysVOrg;
import com.ce.sys.person.dao.po.SysPerson;
import com.ce.util.DbUtil;
import com.ce.util.DictUtil;
import com.ce.util.FlowPicView;
import com.ce.util.FlowWorkUtil;
import com.ce.util.NetFileUtil;
import com.ce.util.OrgUtil;
import com.ce.util.RegeditUtil;
import com.ce.util.TreeNode;
import com.ce.workflow.work.dao.po.WorkflowFlow;
import com.ce.workflow.work.dao.po.WorkflowMan;
import com.ce.workflow.work.dao.po.WorkflowWork;


/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2014-03-18
* 创建时间：15:29:27
* 功能描述：备选案源台账 [CASE_SOURCE]更改时用的Action
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class CaseSourceReceiveAction extends DataMaintainAction 
{
	private static final long serialVersionUID = 1L;
	
	private CaseSourceApprove appr;
	private CaseSourceDrawApprove drawAppr;
	
	@Override
	protected void initOtherData(boolean isNew) {
		if(isNew){
			User user=User.getUser();
			String orgLevel=user.getRootOrgLevel();
			try {
				BeanAccessUtil.copyProperty(po, "registerPerson", User.getUserName());
				BeanAccessUtil.copyProperty(po, "registerDate", new Date());
//				if("2".equals(orgLevel)){
//					BeanAccessUtil.copyProperty(po, "registerDate", new Date());
//				}
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
			
			
		}
	}
	@Override
	protected String addItem() throws AppException {
		try {
			BeanAccessUtil.copyProperty(po, "registerDeptId", User.getUserOrgId());
			BeanAccessUtil.copyProperty(po, "registerDeptName", User.getUserOrgName());
			BeanAccessUtil.copyProperty(po, "state", "0");
			BeanAccessUtil.copyProperty(po, "stateInfo", "备选案源");
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return super.addItem();
	}
	@Override
	protected String modifyItem() throws AppException {
		//避免将流程状态暴漏给页面，避免非法篡改
		AbstractPO entiy=(AbstractPO)this.baselogic.getPOByPk(po.getClass().getName(), po.getVcId());
		BeanAccessUtil.copyNoCopyNullProperty(po, entiy);
		this.baselogic.updatePo(entiy,this.getAddList(),this.getModifyList(),this.getDeleteList());
	    return super.searchData();			
	}
	@Override
	public String look() throws AppException {
		super.look();
		return WebConstants.REQUEST_LOOKDATA_OPERATOR;
	}
	////
	public String openZcdcPage(){
		User user=User.getUser();
		String vcId=this.getParameter("chkSelf");
		this.setAttribute("vcId", vcId);//		
		return "openZcdcPage";
	}
	public String saveDcSuccessed(){
		String vcId=this.getParameter("vcId");
		String vcAdvance=this.getParameter("vcAdvance");
		CaseSource po=new CaseSource();
		User user=User.getUser();
		try {
			po=(CaseSource)this.baselogic.getPOByPk(po.getClass().getName(), vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		}
		WorkflowWork work=FlowWorkUtil.getWorkflowWork(vcId);
		if(work!=null){
			work.setVcStatus("-2");//暂存待查
			work.setVcHandleDate(new Date());
			work.setVcHandleInfo(vcAdvance);
			WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowByPerson(vcId, user.getUserId());
			if(flow!=null){
				flow.setVcStatus("2");
				try {
					this.baselogic.updatePo(flow);
				} catch (AppException e) {
					e.printStackTrace();
				}
			}
			
			try {
				this.baselogic.updatePo(work);
			} catch (AppException e) {
				e.printStackTrace();
			}
		}
		
		
		FlowWorkUtil.saveWorkflowMan(vcId, vcAdvance);
		return this.returnInfoForJS(true, null);
	}
	
	
	
	/**
	 * 重新启动
	 * @return
	 */
	public String saveNewStartSuccessed(){
		String vcId=this.getParameter("chkSelf");
		CaseSource po=new CaseSource();
		User user=User.getUser();
		try {
			po=(CaseSource)this.baselogic.getPOByPk(po.getClass().getName(), vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		}
		WorkflowWork work=FlowWorkUtil.getWorkflowWork(vcId);
		
		WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowByPerson(vcId, user.getUserId());
		flow.setVcStatus("1");//设置为处理中		
		work.setVcStatus(flow.getVcSequence().toString());//设置当前环节。
		work.setVcHandleDate(new Date());
		work.setVcHandleInfo("重启");
		try {
			this.baselogic.updatePo(work);
			this.baselogic.updatePo(flow);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		FlowWorkUtil.saveWorkflowMan(vcId, "重新启动");
		return this.returnInfoForJS(true, "重启成功！");
	}
	
	
	public String saveEndSuccessed(){
		String vcId=this.getParameter("chkSelf");
		CaseSource po=new CaseSource();
		User user=User.getUser();
		try {
			po=(CaseSource)this.baselogic.getPOByPk(po.getClass().getName(), vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		}
		WorkflowWork work=FlowWorkUtil.getWorkflowWork(vcId);
		work.setVcStatus("9");//结案
		work.setVcHandleDate(new Date());
		work.setVcHandleInfo("结案");
		WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowByPerson(vcId, user.getUserId());
		flow.setVcStatus("2");
		try {
			this.baselogic.updatePo(work);
			this.baselogic.updatePo(flow);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		FlowWorkUtil.saveWorkflowMan(vcId, "结案");
		return this.returnInfoForJS(true, "结案成功！");
	}
	
	public String saveStopSuccessed(){
		String vcId=this.getParameter("chkSelf");
		String vcEndType=this.getParameter("vcEndType");
		CaseSource po=new CaseSource();
		User user=User.getUser();
		try {
			po=(CaseSource)this.baselogic.getPOByPk(po.getClass().getName(), vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		}
		po.setVcEndType(vcEndType);
		try {
			this.baselogic.updatePo(po);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		String endContent="";
		if("1".equals(vcEndType))
			endContent="中止检查";
		else if("2".equals(vcEndType))
			endContent="终止检查";
		else if("3".equals(vcEndType))
			endContent="中止执行";	
		else if("3".equals(vcEndType))
			endContent="终止执行";
		FlowWorkUtil.saveWorkflowMan(vcId, endContent);
		return this.returnInfoForJS(true, "操作成功！");
	}
	
	public String openShPage(){
		User user=User.getUser();
		String vcId=this.getParameter("chkSelf");
		String vcPosition=user.getVcPosition();//职务
		this.setAttribute("vcId", vcId);//
		this.setAttribute("vcPosition", vcPosition);//01  局长  02  副局长
		List<SysPerson> persons=OrgUtil.getUserByOrgId("15009070700", true);
		this.setAttribute("persons", persons);
		return "openShPage";
	}
	public String saveShSuccessed(){
		String vcId=this.getParameter("vcId");
		String shFlag=this.getParameter("shFlag");
		String vcAdvance=this.getParameter("vcAdvance");
		CaseSource po=new CaseSource();
		User user=User.getUser();
		String vcPosition=user.getVcPosition();//职务
		
		try {
			po=(CaseSource)this.baselogic.getPOByPk(po.getClass().getName(), vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		}
		po.setStateInfo(vcAdvance);
		if("02".equals(vcPosition)){//副局
			if("1".equals(shFlag)){
				po.setState(2);//同意
				FlowWorkUtil.updateFlowWork(vcId, "15009070700", OrgUtil.getOrgName("15009070700"), "15009030001", OrgUtil.getUserName("15009030001"),vcAdvance);
			}else{
				po.setState(-1);//驳回
				WorkflowWork work=FlowWorkUtil.getWorkflowWork(vcId);
				FlowWorkUtil.updateFlowWork(vcId, work.getVcOrgId(), work.getVcOrgName(), work.getVcPersonId(), work.getVcPersonName(),vcAdvance);
			}
		}else{//局长审批
			if("1".equals(shFlag)){
				po.setState(3);//同意
			}else{
				po.setState(-2);//驳回
			}
			WorkflowWork work=FlowWorkUtil.getWorkflowWork(vcId);
			FlowWorkUtil.updateFlowWork(vcId, work.getVcOrgId(), work.getVcOrgName(), work.getVcPersonId(), work.getVcPersonName(),vcAdvance);
		}
		try {
			this.baselogic.updatePo(po);
		} catch (AppException e) {
			e.printStackTrace();
		}		
		return this.returnInfoForJS(true, null);
	}
	public String lookItemFrame(){
		
		SysVOrg curorg=OrgUtil.getOrg(User.getUserOrgId());
		this.setAttribute("orgType", curorg.getVcOrgLevel());
		String vcId=this.getParameter("chkSelf");
		CaseSource po=null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(CaseSource.class.getName(), vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		WorkflowWork work=FlowWorkUtil.getWorkflowWork(vcId);
		if(work!=null){
			User user=User.getUser();
			
			
			WorkflowFlow flowing=FlowWorkUtil.getWorkflowFlowByPersonCling(vcId, user.getUserId());//当前人正在处理的节点
			
			WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowByPerson(vcId, user.getUserId());
			//显示同意撤销按钮
			if(user.getVcId().equals(po.getVcDownmanId())&&"1".equals(po.getVcRevocation()))
			{
				this.setAttribute("showShRevocationButton", "true");
			}
			
			int endType=0;
			if(flowing!=null){
				if(StringUtil.isNotBlank(po.getVcEndType()))
					endType=Integer.parseInt(po.getVcEndType());
				if(flowing.getVcSequence()==2){//检查环节
					if(endType==0){//中止检查{
						this.setAttribute("showStopCheckButton", "true");
						this.setAttribute("showEndCheckButton", "true");
					}
					if(endType==1){
						this.setAttribute("showEndCheckButton", "true");
					}
					
				}
				if(flowing.getVcSequence()==4){//执行环节
					if(endType==0){//中止检查{
						this.setAttribute("showStopExecButton", "true");
						this.setAttribute("showEndExecButton", "true");	
					}
					if(endType==3){
						this.setAttribute("showEndExecButton", "true");
					}
				}
			}
			
			if(user.getVcId().equals(work.getVcHandlePersonId())){
				if("-2".equals(work.getVcStatus())){//暂存待查的案件
					this.setAttribute("showBtnNewButton", "true");
				}
				if(3==po.getState()&&RegeditUtil.getRegeditStringValue("SYSTEM_SEG_ID").equals(user.getRootOrgId())){//是否显示审核按钮，案源下发之前，选案科、主管局长、局长的审核步骤。
					this.setAttribute("showBtnDown","true");//下发按钮
				}
				if(3==po.getState()&&"3".equals(OrgUtil.getOrg(user.getVcOrgId()).getVcOrgLevel())){//跨区稽查局科室人员的按钮
					this.setAttribute("showBtnQs", "true");//签收
					if(flow!=null&&1!=flow.getVcSequence().intValue()){//选案岗 撤销操作按钮
						this.setAttribute("showBtnHt", "true");
					}
					
					
					this.setAttribute("showBtnYj", "true");
				}
				
				if((0!=po.getState())&&"15009070700".equals(user.getVcOrgId())){//市局局长室审核
					this.setAttribute("showBtnSh", "true");
				}
			}
			
			
			if(!"-2".equals(work.getVcStatus())){//暂存待查的案件
				if(flow!=null&&1==flow.getVcSequence().intValue()){//选案岗
					this.setAttribute("showBtnZcdcButton", "true");
				}
				
			}
			if(!"9".equals(work.getVcStatus())){//未结案  撤销操作按钮
				if(flow!=null&&1==flow.getVcSequence().intValue()){//选案岗 撤销操作按钮
					this.setAttribute("showRevocationButton", "true");
				}
				if(flow!=null&&1==flow.getVcSequence().intValue()){//选案岗 合并操作按钮/
					this.setAttribute("showJoinButton", "true");
				}
			}
			if(flow!=null&&(4==flow.getVcSequence()||3==flow.getVcSequence())){
				this.setAttribute("showBtnEnd", "true");
			}
		}
		if(StringUtil.isNotBlank(po.getReportId()))
			this.setAttribute("showBtnReport", "true");
		
		
		return "lookItemFrame";
	}
	public void wsTree(){
		String vcRecordId=this.getParameter("vcRecordId");
		User user=User.getUser();
		String hql="from CaseSourceFiles t where t.vcRecordId='"+vcRecordId+"'";
		WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowByPerson(vcRecordId, User.getUserId());
		if("2".equals(user.getRootOrgLevel())&&flow!=null)
		{
			if("3".equals(user.getOrgLevel())&&("08".equals(user.getVcPosition())||"09".equals(user.getVcPosition())||"10".equals(user.getVcPosition()))){//库区局科长、副科长、科员
				int n=flow.getVcSequence();
				if(n>1){//第二个节点
					hql+=" and (t.vcSequence='"+n+"' or t.vcSequence='"+(n-1)+"')";
				}else{
					hql+=" and t.vcSequence='"+n+"'";
				}
			}
				
		}else if("3".equals(user.getRootOrgLevel()))
		{
				hql+=" and t.vcZgswj='2'";//征管局可看。
		}
		hql+=" order by t.dtDate";
		List<CaseSourceFiles>  files=new ArrayList<CaseSourceFiles>();
		try {
			files=(List<CaseSourceFiles>) this.baselogic.searchByHql(hql);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JSONArray jsonTree = new JSONArray();
		List<JsonTreeNode> fileList = new ArrayList<JsonTreeNode>();
		JsonTreeNode rootNode=new JsonTreeNode();
		rootNode.setId("1");
		rootNode.setIconCls("ext-icon-book_open");
		rootNode.setText("案源文书");
		rootNode.setState("open");
		if(files!=null&&files.size()>0){
			for(CaseSourceFiles file:files){
				JsonTreeNode child = new JsonTreeNode();
            	child.setId(file.getVcFileId());
            	child.setText(file.getVcFileName());
            	child.setIconCls("ext-icon-book_open");
            	fileList.add(child);
			}
			rootNode.setChildren(fileList);
		}
		List<JsonTreeNode> nodeList = new ArrayList<JsonTreeNode>();
		nodeList.add(rootNode);
		jsonTree.add(nodeList); // 写入树节点信息
		// 以字符串为文件流进行输出
		// 由于形成的json格式与easyui的格式在外部多了个[]，因此在这里进行移除。
		writeHTML(jsonTree.toString().substring(1, jsonTree.toString().length() - 1).toString()); // 将树以JSON格式的字符串进行输出

		
	}
	public String caseSourceHandOver(){
		String chkSelf=this.getParameter("chkSelf");
		WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowByPerson(chkSelf, User.getUserId());
		if(flow!=null&&"2".equals(flow.getVcStatus()))
		{
			return this.writeHTML("不能重复移交！");
		}
		else{
			String vcParId=User.getParOrgIdByOrgLevel("2");
			List<SysVOrg> deps=OrgUtil.getChildDep(vcParId);
			
			StringBuffer op = new StringBuffer();
			if(deps!=null&&deps.size()>0){
				for(SysVOrg org:deps){
					    op.append("<option value='"+org.getVcId()+"'>"+org.getVcName()+"</option>");
				}
				
			}else{
				op.append("<option value=''></option>");
			}
			this.setAttribute("deps", deps);
			return "caseSourceHandOver";
		}
		
	}
	
	public String handOverSuccessed(){
		String chkSelf=this.getParameter("chkSelf");
		String[] userids = this.getParameterValues("userIds[]");
		String[] username=this.getParameterValues("idnames[]");
		String vcOrgId=this.getParameter("vcOrgId");
		String vcType=this.getParameter("vcType");
		String vcAdvance=this.getParameter("vcAdvance");
		SysVOrg org=OrgUtil.getOrg(vcOrgId);
		CaseSource po=null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(CaseSource.class.getName(), chkSelf);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		FlowWorkUtil.transferFlowWork(chkSelf, vcType, User.getUserId(), "", "", vcOrgId, org.getVcName(), userids[0], username[0], vcAdvance);		
		return this.returnInfoForJS(true, null);
	}
	/**
	 * 案源签收，置状态为处理中1
	 * @return
	 */
	public String caseSourceReceiveSuccess(){
		String chkSelf=this.getParameter("chkSelf");
		WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowStatuIs0ByPerson(chkSelf, User.getUserId());
		SysVOrg org=OrgUtil.getOrg(User.getUserOrgId());
		User user=User.getUser();
		if(flow!=null&&("0".equals(flow.getVcStatus())||"3".equals(flow.getVcStatus())))
		{
			if("0".equals(flow.getVcStatus())){//第一次签收
				List<CaseSourceFilesTemplate> l= FlowWorkUtil.getWorkflowTemplateFiles(""+flow.getVcSequence(), "1");//重要的文书
				String fileIds[]=null;
				if(l!=null&&l.size()>0){
					fileIds=new String [l.size()];
					for(int i=0;i<l.size();i++){
						fileIds[i]=l.get(i).getVcFileId();
					}
				}
				
				if(fileIds!=null){
					List<PubFileUploadLog> l_=NetFileUtil.getPubFileUploadLogs(fileIds);
					for(int i=0;i<l_.size();i++){
						PubFileUploadLog log=new PubFileUploadLog();
						CaseSourceFiles files=new CaseSourceFiles();
						String fileName=l_.get(i).getVcFilename();
						int m=fileName.lastIndexOf(".");
						String fileType=fileName.substring(m, fileName.length());
						String sourceFilePath=FrameworkContext.getAppPath()+l_.get(i).getVcChildFolder()+l_.get(i).getVcId()+fileType;
						String yyyyMMddpath=DateUtil.format(new Date(), "yyyy")+"/"+DateUtil.format(new Date(), "MM")+"/"+DateUtil.format(new Date(), "dd");
						String fileId=GeneratorUUID.generateUUID();
						String dicPath=FrameworkContext.getAppPath()+"approve/"+yyyyMMddpath+"/"+fileId+fileType;
						File saveFile = new File(FrameworkContext.getAppPath()+"approve/"+yyyyMMddpath+"/");
						if (!saveFile.exists())
							saveFile.mkdirs();
						files.setVcId(GeneratorUUID.generateUUID());
						files.setDtDate(new Date());
						files.setVcBrowse(l.get(i).getVcBrowse());
						files.setVcSequence(l.get(i).getVcSequence());
						files.setVcTemplateId(l.get(i).getVcId());
						files.setVcFileId(fileId);
						files.setVcFileName(fileName);
						files.setVcFlowId(flow.getVcId());
						files.setVcRecordId(chkSelf);
						files.setVcZgswj(l.get(i).getVcZgswj());
						files.setVcOrgId(User.getUserOrgId());
						files.setVcOrgName(org.getVcName());
						files.setVcPersonId(User.getUserId());
						files.setVcPersonName(User.getUserName());
						files.setVcJcjId(user.getRootOrgId());
						files.setVcJdjName(OrgUtil.getOrg(user.getRootOrgId()).getVcName());
						files.setVcDelFlag("0");
						
						log.setVcFilename(fileName);
						log.setVcId(fileId);
						log.setVcChildFolder("approve/"+yyyyMMddpath+"/");
						log.setVcDelFlag(0);
						
						DbUtil.addPo(log);
						DbUtil.addPo(files);
						FileUtil.copyFile(sourceFilePath, dicPath);
					}
				}
			}
			
			
			FlowWorkUtil.setReceiveFlag(chkSelf,User.getUserOrgId(),User.getUserOrgName(),User.getUserId(),User.getUserName());
		}
		else{
			return this.returnInfoForJS(false, "该案源已经签收，不能重复操作！");
		}
		return this.returnInfoForJS(true, "签收成功！");
	}
	
	public String ajaxPersons(){
		String vcOrgId=this.getParameter("vcOrgId");
		List<SysPerson> persons=OrgUtil.getUserByOrgId(vcOrgId, true);
		this.rows=persons;
		return JSON;
	}
	public String ajaxOrgs(){
		String vcOrgId=this.getParameter("vcOrgId");
		List<SysVOrg> orgs=OrgUtil.getChildDep(vcOrgId);
		this.rows=orgs;
		return JSON;
	}
	/**
	 * 案源退回界面
	 * @return
	 */
	public String caseSourceGoBack(){
		return "caseSourceGoBack";
	}
	
	/**
	 * 案源退回操作
	 * @return
	 */
	public String caseSourceGoBackSuccess(){
		String vcId=this.getParameter("chkSelf");
		String vcAdvance=this.getParameter("vcAdvance");
		
		String chkSelf=this.getParameter("chkSelf");
		WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowByPerson(chkSelf, User.getUserId());
		if(flow!=null&&("0".equals(flow.getVcStatus())||"1".equals(flow.getVcStatus())))
		{
			if(1==flow.getVcSequence().intValue()){
				return this.returnInfoForJS(false, "回退失败！案源不允许回退至市局。");
			}
			FlowWorkUtil.backFlowWork(vcId,  User.getUserOrgId(), User.getUserOrgName(), User.getUserId(), User.getUserName(), "退回："+vcAdvance);
		}
		else{
			if(flow==null){
				return this.returnInfoForJS(false, "回退失败！案源不允许重复回退。");
			}
			if(1==flow.getVcSequence().intValue()){
				return this.returnInfoForJS(false, "回退失败！案源不允许回退至市局。");
			}
			//return this.alertMsg("该案源已经签收，不能重复操作！");
			return this.returnInfoForJS(false, "回退失败！只有未签收或者已签收未向下一环节移交的案源才能回退。");
		}
		
		return this.returnInfoForJS(true, "回退成功！");
	}
	
	public String caseSourceReceiveColumn(){
		String sql="select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9') and t.INSPECTION_DEPT_ID='15007010000' group by w.vc_status order by w.vc_status";//第一稽查局  15007010000
		//List<String> first=DbUtil.executeStringSqlQuery(sql);
		final Map<String,Integer> first_=new HashMap<String,Integer>();
		DbUtil.executeSqlQuery(sql, new ISQLMapper(){
			
			@Override
			public Object fromSQLQuery(ResultSet rs, int num) {
				TreeNode node=new TreeNode();
				try {
					first_.put(rs.getString("vc_status"), rs.getInt("cnt"));
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				return node;
			}
			
		});
		
		this.setAttribute("first", first_);
		sql="select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9') and t.INSPECTION_DEPT_ID='15007020000' group by w.vc_status order by w.vc_status";//第二稽查局  15007020000
		final Map<String,Integer> second_=new HashMap<String,Integer>();
		List<TreeNode> second=DbUtil.executeSqlQuery(sql, new ISQLMapper(){

			@Override
			public Object fromSQLQuery(ResultSet rs, int num) {
				TreeNode node=new TreeNode();
				try {
					second_.put(rs.getString("vc_status"), rs.getInt("cnt"));
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return node;
			}
			
		});
		this.setAttribute("second", second_);
		sql="select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9') and t.INSPECTION_DEPT_ID='15007030000' group by w.vc_status order by w.vc_status";//第三稽查局  15007030000
		final Map<String,Integer> three_=new HashMap<String,Integer>();
		List<TreeNode> three=DbUtil.executeSqlQuery(sql, new ISQLMapper(){

			@Override
			public Object fromSQLQuery(ResultSet rs, int num) {
				TreeNode node=new TreeNode();
				try {
					three_.put(rs.getString("vc_status"), rs.getInt("cnt"));
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return node;
			}
			
		});
		this.setAttribute("three", three_);
		sql="select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9') and t.INSPECTION_DEPT_ID='15007040000' group by w.vc_status order by w.vc_status";//第四稽查局  15007040000
		final Map<String,Integer> four_=new HashMap<String,Integer>();
		List<TreeNode> four=DbUtil.executeSqlQuery(sql, new ISQLMapper(){

			@Override
			public Object fromSQLQuery(ResultSet rs, int num) {
				TreeNode node=new TreeNode();
				try {
					four_.put(rs.getString("vc_status"), rs.getInt("cnt"));
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return node;
			}
			
		});
		this.setAttribute("four", four_);
		sql="select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9') and t.INSPECTION_DEPT_ID='15007050000' group by w.vc_status order by w.vc_status";//第五稽查局  15007050000
		final Map<String,Integer> five_=new HashMap<String,Integer>();
		List<TreeNode> five=DbUtil.executeSqlQuery(sql, new ISQLMapper(){

			@Override
			public Object fromSQLQuery(ResultSet rs, int num) {
				TreeNode node=new TreeNode();
				try {
					five_.put(rs.getString("vc_status"), rs.getInt("cnt"));
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return node;
			}
			
		});
		this.setAttribute("five", five_);
		
//		List<String> first=new ArrayList<String>();
//		first.add("2");first.add("8");first.add("20");first.add("5");first.add("7");
//		this.setAttribute("first", first.toString());
//		
//		List<String> second=new ArrayList<String>();
//		second.add("3");second.add("5");second.add("10");second.add("3");second.add("2");
//		this.setAttribute("second", second.toString());
//		
//		List<String> three=new ArrayList<String>();
//		three.add("6");three.add("5");three.add("4");three.add("8");three.add("4");
//		this.setAttribute("three", three.toString());
//		
//		List<String> four=new ArrayList<String>();
//		four.add("8");four.add("3");four.add("11");four.add("4");four.add("5");
//		this.setAttribute("four", four.toString());
//		
//		List<String> five=new ArrayList<String>();
//		five.add("6");five.add("7");five.add("12");five.add("7");five.add("8");
//		this.setAttribute("five", five.toString());
		//return "caseSourceReceiveColumn";
		return "caseSourceReceiveColumn";
	}
	
	public String caseSourceReceiveColumn2(){
		String sql="select count(*) as cnt from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','2','3','4','9')  group by t.INSPECTION_DEPT_ID order by t.INSPECTION_DEPT_ID";//
		List<String> first=DbUtil.executeStringSqlQuery(sql);
		this.setAttribute("first", first.toString());
		
//		List<String> first=new ArrayList<String>();
//		first.add("8");first.add("5");first.add("10");first.add("3");first.add("6");
//		this.setAttribute("first", first.toString());
		return "caseSourceReceiveColumn2";
	}
	public String caseSourceReceiveColumn3(){
		String sql="select count(*) as cnt from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','2','3','4','9')  group by w.vc_status";//
		List<String> first=DbUtil.executeStringSqlQuery(sql);
		this.setAttribute("first", first.toString());
		
//		List<String> first=new ArrayList<String>();
//		first.add("8");first.add("5");first.add("10");first.add("3");
//		this.setAttribute("first", first.toString());
		return "caseSourceReceiveColumn3";
	}
	public String getCaseSourceDb(){
		return "getCaseSourceDb";
	}
	
	public String getCaseSourceDbJs(){
		User user=User.getUser();
		List<CaseSource> list=FlowWorkUtil.getCaseSourceDb(user.getUserOrgId(), user.getUserId());
		this.rows=list;
		return JSON;
	}
	
	
	/**
	 * 案源合并窗口
	 * @return
	 */
	public String openJoinPage(){
		
		String vcId=this.getParameter("chkSelf");
		this.setAttribute("vcId", vcId);//		
		return "openJoinPage";
	}
	
	/**
	 * 合并提交
	 * @return
	 */
	public String caseSourceJoinSuccess(){
		String vcAdvance=this.getParameter("vcAdvance");		
		String chkSelf=this.getParameter("chkSelf");
		
		CaseSource po=null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(CaseSource.class.getName(), chkSelf);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		po.setVcJoin("1");//一合并
		po.setVcJoinman(User.getUserName());
		po.setVcJoinmanId(User.getUserId());
		try {
			this.baselogic.updatePo(po);
		} catch (AppException e) {
			e.printStackTrace();
		}
		FlowWorkUtil.saveWorkflowMan(chkSelf, vcAdvance);
		
		return this.returnInfoForJS(true, "合并成功！");
	}
	
	/**
	 * 案源撤销操作  跨区局选案岗进行操作
	 * @return
	 */
	public String caseSourceRevocation(){
		String vcId=this.getParameter("chkSelf");
		this.setAttribute("vcId", vcId);//		
		
		return "openRevocationPage";
	}
	/**
	 * 撤销提请成功
	 * @return
	 */
	public String caseSourceRevocationSuccess(){
		String vcAdvance=this.getParameter("vcAdvance");		
		String chkSelf=this.getParameter("chkSelf");
		
		CaseSource po=null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(CaseSource.class.getName(), chkSelf);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		po.setVcRevocation("1");
		try {
			this.baselogic.updatePo(po);
		} catch (AppException e) {
			e.printStackTrace();
		}
		FlowWorkUtil.saveWorkflowMan(chkSelf, vcAdvance);
		
		return this.returnInfoForJS(true, "撤销成功！");
	}
	//打开撤销审批界面
	public String openShRevocationPage(){
		User user=User.getUser();
		String vcId=this.getParameter("chkSelf");
		
		this.setAttribute("vcId", vcId);//		
		return "openShRevocationPage";
	}
	
	/**
	 * 案源撤销操作  跨区局选案岗进行操作
	 * @return
	 */
	public String caseSourceShRevocationSuccess(){
		String vcAdvance=this.getParameter("vcAdvance");
		String shFlag=this.getParameter("shFlag");
		String chkSelf=this.getParameter("vcId");		
		CaseSource po=null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(CaseSource.class.getName(), chkSelf);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		po.setVcRevocation(shFlag);
		try {
			this.baselogic.updatePo(po);
		} catch (AppException e) {
			e.printStackTrace();
		}
		FlowWorkUtil.saveWorkflowMan(chkSelf, vcAdvance);
		
		return this.returnInfoForJS(true, "撤销成功！");
	}
	
	public String caseSourceFlowPage(){
		String vcRecordId=this.getParameter("chkSelf");
		List<FlowPicView> list = new ArrayList<FlowPicView>();
		List<WorkflowFlow> flows=FlowWorkUtil.getWorkflowFlows(vcRecordId);
		
		WorkflowFlow o=null;
		String statu="";
		if(flows!=null&&flows.size()>0){
			for(int i=1;i<=flows.size();i++){
				o=flows.get(i-1);
				statu=o.getVcStatus();
				list.add(new FlowPicView(getNodeName(i),"处理人："+flows.get(i-1).getVcHandlePersonName(),"2".equals(statu)?"comp":"1".equals(statu)?"ing":"unf"));
			}
			for(int i=flows.size()+1;i<=4;i++){
				list.add(new FlowPicView(getNodeName(i),"","unf"));
			}
		}else{
			for(int i=1;i<=4;i++){
				list.add(new FlowPicView(getNodeName(i),"","unf"));
			}
		}
		
		
		JSONArray ary = new JSONArray();
		ary.addAll(list);
		setAttribute("flowpic",ary.toString());
		List<WorkflowMan> mans=FlowWorkUtil.getWorkflowMansByRecordId(vcRecordId);
		setAttribute("flows",mans);
		return "caseSourceFlowPage";
	}
	private String getNodeName(int i){
		String info="";
		if(i==1)
			info="选案";
		else if(i==2)
			info="检查";
		else if(i==3)
			info="审理";
		else if(i==4)
			info="执行";
		return info;
	}
	/**
	 * 打开案源下发界面
	 * @return
	 */
	public String caseSourceDown(){
		String vcId=this.getParameter("chkSelf");
		WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowByVcSeq(vcId, "1");
		if(flow!=null)
		{
			return this.alertMsgAndExecJs("该案源已经下发，不能重复操作！", "$('#operateWindow').window('close');");
		}
		else{
			CaseSource source=null;
			try {
				source=(CaseSource)this.baselogic.getPOByPk("com.ce.cases.source.dao.po.CaseSource", vcId);
			} catch (AppException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			List<SysVOrg> deps=OrgUtil.getChildDep(source.getInspectionDeptId());
			
			List<SysPerson> l= OrgUtil.getDefaultUserReceiveCaseByOrgId(source.getInspectionDeptId());
			if(l!=null&&l.size()>0){
				this.setAttribute("default", l.get(0).getVcName());
			}
			
			StringBuffer op = new StringBuffer();
			if(deps!=null&&deps.size()>0){
				for(SysVOrg org:deps){
					    op.append("<option value='"+org.getVcId()+"'>"+org.getVcName()+"</option>");
				}
				
			}else{
				op.append("<option value=''></option>");
			}
			this.setAttribute("deps", deps);
			this.setAttribute("vcId", vcId);
			
			return "caseSourceDown";
			
		}
		//String vcParId=User.getParOrgIdByOrgLevel("1");
		
	}
	//
	public String caseSourceDownSuccess(){
		String vcRecordId=this.getParameter("chkSelf");
		
		String handOverId=this.getParameter("handOverId");
		String handOverName=this.getParameter("handOverName");
		String vcHandleOrgId="",vcHandleOrgName="",vcHandlePersonId="",vcHandlePersonName="";
//		String vcHandleOrgName=OrgUtil.getOrgName(vcHandleOrgId);
//		String vcHandlePersonId=this.getParameter("handOverPersonId");
//		String vcHandlePersonName=this.getParameter("handOverPerson");
		String vcDesc=this.getParameter("vcAdvance");
		vcDesc="下达："+vcDesc;
		String vcType=this.getParameter("vcType");
		
		CaseSource source=null;
		try {
			source = (CaseSource) this.baselogic.getPOByPk(CaseSource.class.getName(), vcRecordId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		source.setState(3);
		SysVOrg jcjorg=OrgUtil.getOrg(source.getInspectionDeptId());
		String year=DateUtil.getYear();
    	String sql="select count(*) from CASE_SOURCE t where t.INSPECTION_DEPT_ID='"+source.getInspectionDeptId()+"' and t.STATE=3 and t.vc_del$flag='0'";
    	int cnt=DbUtil.getFirstIntSqlQuery(sql);
    	String cnt_="";
    	if(cnt<10)
    		cnt_="00"+cnt;
    	else if(cnt<100)
    		cnt_="0"+cnt;
    	else 
    		cnt_=""+cnt;
    	source.setCaseNumber(year+"-J"+jcjorg.getNseq()+"-"+cnt_);
    	source.setVcDownmanId(User.getUserId());
    	source.setVcDownman(User.getUserName());
    	try {
			this.baselogic.updatePo(source);
		} catch (AppException e) {
		}
		if("1".equals(vcType)){//下发到人员
			if(StringUtil.isBlank(handOverId)){
				List<SysPerson> l= OrgUtil.getDefaultUserReceiveCaseByOrgId(source.getInspectionDeptId());
				SysPerson person=null;
				if(l!=null&&l.size()>0){
					person=l.get(0);
				}
				if(person!=null){
					vcHandlePersonId=person.getVcId();
					vcHandlePersonName=person.getVcName();
				}
			}else{
				vcHandlePersonId=handOverId;			
				vcHandlePersonName=handOverName;
			}
			
			
			vcHandleOrgId=OrgUtil.getOrgIdByUserId(vcHandlePersonId);
			vcHandleOrgName=OrgUtil.getOrgNameByUserId(vcHandlePersonId);
			FlowWorkUtil.setDownFlowWork(vcRecordId,vcType,User.getUserOrgId(),User.getUserOrgName(),User.getUserId(),User.getUserName(), vcHandleOrgId, vcHandleOrgName, vcHandlePersonId, vcHandlePersonName, vcDesc);
		}else{
			vcHandleOrgId=handOverId;
			vcHandleOrgName=handOverName;
			FlowWorkUtil.setDownFlowWork(vcRecordId,vcType,User.getUserOrgId(),User.getUserOrgName(),User.getUserId(),User.getUserName(), vcHandleOrgId, vcHandleOrgName, vcHandlePersonId, vcHandlePersonName, vcDesc);
		}
			
		
		return this.returnInfoForJS(true, null);
	}	
	
	public String showCaseSourceFile(){
		String vcId=this.getParameter("chkSelf");
		String vcType=this.getParameter("vcType");
		String vcFileId=this.getParameter("vcFileId");
		String vcFileName=this.getParameter("fileName");
		String fileType="";
		if(vcFileName.contains("."))
			fileType=vcFileName.substring(vcFileName.indexOf("."), vcFileName.length());
		this.setAttribute("fileType", fileType);
		this.setAttribute("vcFileName", vcFileName);
		String filePath="";
		try {
			filePath=NetFileUtil.getFileServerPath(vcFileId);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		this.setAttribute("filePath", filePath);
		List<CaseSourceFiles> l=new ArrayList<CaseSourceFiles>();
		String hql="from CaseSourceFiles p where p.vcFileId='"+vcFileId+"' and p.vcDelFlag='0' ";
		try {
			l=(List<CaseSourceFiles>) this.baselogic.searchByHql(hql);
		} catch (AppException e) {
		}
		if(l!=null&&l.size()>0){
			if(l.get(0).getVcPersonId().equals(User.getUserId())){
				this.setAttribute("readonly", "true");
			}else{
				this.setAttribute("readonly", "false");
			}
		}else{
			this.setAttribute("readonly", "false");
		}
		return "showCaseSourceFile";
	}
	//上传文书
	public String checkNoticePage(){
		String vcId=this.getParameter("chkSelf");
		String fileType=this.getParameter("fileType");
		CaseSource casePo=null;
		try {
			casePo=(CaseSource) this.baselogic.getPOByPk(CaseSource.class.getName(), vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		WorkflowFlow flow=FlowWorkUtil.getCurOrgWorkflowFlow(vcId);
		if(flow!=null){
			this.setAttribute("vcSequence", flow.getVcSequence());
		}
		this.setAttribute("po", casePo);
		this.setAttribute("fileType", fileType);
		this.setAttribute("userName", User.getUserName());
		this.setAttribute("dtDate", DateUtil.format(new Date(), "yyyy年MM月dd日"));
		return "caseCheckNoticePage";
	}
	/*
	 * 上传文书
	 */
	public String addCheckNotice() throws AppException{
		String vcRecordId=this.getParameter("vcRecordId");
		String vcFileId=this.getParameter("fileId");
		WorkflowFlow flow=FlowWorkUtil.getCurOrgWorkflowFlow(vcRecordId);
//		String vcFileName=this.getParameter("fileName");
//		String fileIds[]=vcFileId.split(",");
//		String fileNames[]=vcFileName.split(",");
//		WorkflowFlow flow=FlowWorkUtil.getCurOrgWorkflowFlow(vcRecordId);
//		CaseSourceFiles file=new CaseSourceFiles();
//		for(int i=0;i<fileIds.length;i++){
//			file.setVcId(GeneratorUUID.generateUUID());
//			file.setDtDate(new Date());
//			file.setVcDelFlag("0");
//			file.setVcOrgId(User.getUserOrgId());
//			file.setVcOrgName(User.getUserOrgName());
//			file.setVcPersonId(User.getUserId());
//			file.setVcPersonName(User.getUserName());
//			file.setVcFileId(fileIds[i]);
//			file.setVcFileName(fileNames[i]);
//			file.setVcRecordId(vcRecordId);
//			if(flow!=null)
//				file.setVcFlowId(flow.getVcId());
//			baselogic.addPo(file);
//			FlowWorkUtil.saveWorkflowMan(vcRecordId,"上传"+fileNames[i]);
//		}
		
		
		
		
		//第一次签收
		CaseSourceFilesTemplate fileTemplate=(CaseSourceFilesTemplate)this.baselogic.getPOByPk(CaseSourceFilesTemplate.class.getName(), vcFileId);
		
		
		
		if(fileTemplate!=null){
			SysVOrg org=OrgUtil.getOrg(User.getUserOrgId());
			User user=User.getUser();
			List<PubFileUploadLog> l_=NetFileUtil.getPubFileUploadLogs(new String[]{fileTemplate.getVcFileId()});
			for(int i=0;i<l_.size();i++){
				PubFileUploadLog log=new PubFileUploadLog();
				CaseSourceFiles files=new CaseSourceFiles();
				String fileName=l_.get(i).getVcFilename();
				int m=fileName.lastIndexOf(".");
				String fileType=fileName.substring(m, fileName.length());
				String sourceFilePath=FrameworkContext.getAppPath()+l_.get(i).getVcChildFolder()+l_.get(i).getVcId()+fileType;
				String yyyyMMddpath=DateUtil.format(new Date(), "yyyy")+"/"+DateUtil.format(new Date(), "MM")+"/"+DateUtil.format(new Date(), "dd");
				String fileId=GeneratorUUID.generateUUID();
				String dicPath=FrameworkContext.getAppPath()+"approve/"+yyyyMMddpath+"/"+fileId+fileType;
				File saveFile = new File(FrameworkContext.getAppPath()+"approve/"+yyyyMMddpath+"/");
				if (!saveFile.exists())
					saveFile.mkdirs();
				
				log.setVcFilename(fileName);
				log.setVcId(fileId);
				log.setVcChildFolder("approve/"+yyyyMMddpath+"/");
				log.setVcDelFlag(0);
				
				files.setVcId(GeneratorUUID.generateUUID());
				files.setDtDate(new Date());
				files.setVcBrowse(fileTemplate.getVcBrowse());
				files.setVcSequence(fileTemplate.getVcSequence());
				files.setVcTemplateId(fileTemplate.getVcId());
				files.setVcFileId(fileId);
				files.setVcFileName(fileTemplate.getVcFileName());
				if(flow!=null)
					files.setVcFlowId(flow.getVcId());
				files.setVcRecordId(vcRecordId);
				files.setVcZgswj(fileTemplate.getVcZgswj());
				files.setVcOrgId(User.getUserOrgId());
				files.setVcOrgName(org.getVcName());
				files.setVcPersonId(User.getUserId());
				files.setVcPersonName(User.getUserName());
				files.setVcJcjId(user.getRootOrgId());
				files.setVcJdjName(OrgUtil.getOrg(user.getRootOrgId()).getVcName());
				files.setVcDelFlag("0");
				
				DbUtil.addPo(log);
				DbUtil.addPo(files);
				FileUtil.copyFile(sourceFilePath, dicPath);
				FlowWorkUtil.saveWorkflowMan(vcRecordId,"上传"+fileName);
			}
		}
	
		
		
		
		
		
		return this.returnInfoForJS(true, "上传成功!");
	}
	
	/*
	 * 处理审批页面
	 */
	public String dealApprovePage() throws AppException{
		String caseId=this.getParameter("caseId");
		CaseSource source=(CaseSource)this.baselogic.getPOByPk("com.ce.cases.source.dao.po.CaseSource", caseId);
		List approveList=this.baselogic.searchByHql("From CaseSourceApprove po where po.caseId='"+caseId+"' and po.vcDelFlag=0");
		if(!approveList.isEmpty()){
			appr=(CaseSourceApprove)approveList.get(0);
		}else{
			appr=new CaseSourceApprove();
			appr.setCaseId(source.getVcId());
			appr.setCaseFrom(source.getCaseFromName());
			appr.setCaseNum(source.getCaseNumber());
			appr.setInvolvedEnterprice(source.getInvolvedEnterprice());
			appr.setTaxpayerNumber(source.getTaxpayerNumber());
		}
		return "dealApprovePage";
	}
	
	/*
	 * 处理审批操作
	 */
	public String dealApprove() {
		try {
			// 修改审批表
			if (StringUtil.isNotBlank(appr.getVcId())) {
				appr.setVcDelFlag(0);
				this.baselogic.updatePo(appr);
			} else {// 添加审批表
				appr.setVcId(GeneratorUUID.generateUUID());
				appr.setVcDelFlag(0);
				this.baselogic.addPo(appr);
			}
		} catch (AppException e) {
			LogUtil.logError(e);
			return this.returnInfoForJS(false,
					e.getMessage().replaceAll("'|\\n", " "));
		}
		return this.returnInfoForJS(true, null);
	}
	
	
	/*
	 * 打开检查查看页面
	 */
	public String openCheckPage() throws AppException{
		String caseId=this.getParameter("chkSelf");
		String hql=" from CaseSourceCheck p where p.vcDelFlag='0' and p.caseId='"+caseId+"'";
		List<CaseSourceCheck> l=(List<CaseSourceCheck>) this.baselogic.searchByHql(hql);
		
		if(l!=null&&l.size()>0){
			this.po=l.get(0);
		}else{
			
		}
			
		
		List<SysDictItem> itemList=DictUtil.getDictListByName("检查案源台账-采取措施");
		this.setAttribute("itemList", itemList);
		return "openCheckPage";
	}
	
	/*
	 * 打开执行查看页面
	 */
	public String openExceutePage() throws AppException{
		String caseId=this.getParameter("chkSelf");
		String hql=" from CaseSourceExecute p where p.vcDelFlag='0' and p.caseId='"+caseId+"'";
		List<CaseSourceExecute> l=(List<CaseSourceExecute>) this.baselogic.searchByHql(hql);
		
		if(l!=null&&l.size()>0){
			this.po=l.get(0);
		}else{
			
		}
		
		return "openExceutePage";
	}
	
	/*
	 * 打开举报查看页面
	 */
	public String openReportPage() throws AppException{
		String caseId=this.getParameter("chkSelf");
		CaseSource source=(CaseSource)this.baselogic.getPOByPk("com.ce.cases.source.dao.po.CaseSource", caseId);
		
		String hql=" from ReportTaxIllegal p where p.vcDelFlag='0' and p.vcId='"+source.getReportId()+"'";
		List<CaseSourceExecute> l=(List<CaseSourceExecute>) this.baselogic.searchByHql(hql);
		//this.getUser()
		if(l!=null&&l.size()>0){
			this.po=l.get(0);
		}else{
			
		}
		
		return "openReportPage";
	}
	/*
	 * 打开纳税人查看页面
	 */
	public String openNsrPage() throws AppException{
		String caseId=this.getParameter("chkSelf");
		CaseSource source=(CaseSource)this.baselogic.getPOByPk("com.ce.cases.source.dao.po.CaseSource", caseId);
		
		
		
//		String sql="select t.* from EXPORT_TABLE t where t.NSRSBH='"+source.getTaxpayerNumber()+"'";
//		Connection con=null;
//		try {
//			con=DbUtil.getConnection(Class.forName("oracle.jdbc.driver.OracleDriver"), "jdbc:oracle:thin:@127.0.0.1:1521:csmisdb", "cqgsjc412", "csmis");
//		} catch (ClassNotFoundException e1) {
//			e1.printStackTrace();
//		} catch (Exception e1) {
//			e1.printStackTrace();
//		}
//		if(con!=null){
//			System.out.println(con.toString());
//		}
//		
		
		
		Connection con=null;
		try {
			con=DbUtil.getConnection(Class.forName("oracle.jdbc.driver.OracleDriver"), "jdbc:oracle:thin:@//98.12.102.73:1521/cqsthxqf", "wsbs_ysq", "wsbs_ysq");
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		Statement st=null;
		ResultSet rs=null;
		List<CaseCheckEnterprice> ll=new ArrayList<CaseCheckEnterprice>();
		if(con!=null){
			String sql="select t.* from hx_dj.dj_nsrxx t where t.NSRSBH='"+source.getTaxpayerNumber()+"'";
			try {
				st = con.createStatement();
				rs = st.executeQuery(sql);
				
				while(rs.next()){
					CaseCheckEnterprice po=new CaseCheckEnterprice();
					try {
						po.setTaxpayerNumber(rs.getString("NSRSBH"));
						po.setCertificateNumber(rs.getString("FDDBRHFZRHYZSFZJHM"));
						po.setIndustryName(rs.getString("JYFW"));
						po.setRegisterAddress(rs.getString("SCJYDZ"));//经营地址 
						po.setTaxEnterprice(rs.getString("NSRMC"));//纳税人名称
						po.setLegalPerson(rs.getString("FDDBRHFZRHYZXM"));//法人
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					ll.add(po);
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			}finally{
				try {
					if(rs!=null)
						rs.close();
					if(st!=null)
						st.close();
					if(con!=null)
						con.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
				}
				
			}
			
		}
		
		
		
		
//		//DbUtil.getConnection(driver, dbUrl, userName, userPwd)
//		List<CaseCheckEnterprice> l=DbUtil.executeSqlQuery(sql, new ISQLMapper(){
//
//			@Override
//			public Object fromSQLQuery(ResultSet rs, int num) {
//				CaseCheckEnterprice po=new CaseCheckEnterprice();
//				try {
//					po.setTaxpayerNumber(rs.getString("NSRSBH"));
//					po.setCertificateNumber(rs.getString("FDDBRHFZRHYZSFZJHM"));
//					po.setIndustryName(rs.getString("JYFW"));
//					po.setRegisterAddress(rs.getString("SCJYDZ"));//经营地址 
//					po.setTaxEnterprice(rs.getString("NSRMC"));//纳税人名称
//					po.setLegalPerson(rs.getString("FDDBRHFZRHYZXM"));//法人
//				} catch (SQLException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//				
//				return po;
//			}});
		
		
		if(ll!=null&&ll.size()>0){
			this.po=ll.get(0);
		}else{
			
		}
		
		return "openNsrPage";
	}
	
	
	/*
	 * 提请审批页面
	 */
	public String drawApprovePage() throws AppException{
		String caseId=this.getParameter("caseId");
		CaseSource source=(CaseSource)this.baselogic.getPOByPk("com.ce.cases.source.dao.po.CaseSource", caseId);
		List drawApprList=this.baselogic.searchByHql("From CaseSourceDrawApprove po where po.caseId='"+caseId+"' and po.vcDelFlag=0");
		if(!drawApprList.isEmpty()){
			drawAppr=(CaseSourceDrawApprove)drawApprList.get(0);
		}else{
			drawAppr=new CaseSourceDrawApprove();
			drawAppr.setCaseId(caseId);
			drawAppr.setCaseFromNum(source.getCaseFromNum());
			drawAppr.setCaseFromName(source.getCaseFromName());
			drawAppr.setTaxpayer(source.getInvolvedEnterprice());
			drawAppr.setTaxpayerNumber(source.getTaxpayerNumber());
			drawAppr.setDrawDept(User.getUserOrgName());
		}
		return "drawApprovePage";
	}
	
	/*
	 * 提请审批操作
	 */
	public String drawApprove() throws AppException{
		try {
			// 修改审批表
			if (StringUtil.isNotBlank(drawAppr.getVcId())) {
				drawAppr.setVcDelFlag(0);
				this.baselogic.updatePo(drawAppr);
			} else {// 添加审批表
				drawAppr.setVcId(GeneratorUUID.generateUUID());
				drawAppr.setVcDelFlag(0);
				drawAppr.setDrawDeptId(User.getUserOrgId());
				this.baselogic.addPo(drawAppr);
			}
		} catch (AppException e) {
			LogUtil.logError(e);
			return this.returnInfoForJS(false,
					e.getMessage().replaceAll("'|\\n", " "));
		}
		return this.returnInfoForJS(true, "提请审批操作成功!");
	}
	
	@SuppressWarnings("unchecked")
	public String viewHearResult() throws AppException{
		String caseId=this.getSelectId();
		List<CaseSourceHear> hearList=(List<CaseSourceHear>) this.baselogic.searchByHql("From CaseSourceHear po where po.caseId='"+caseId+"'");
		CaseSourceHear hearPo=null;
	    if(!hearList.isEmpty())
	    	hearPo=hearList.get(0);
		this.setAttribute("po", hearPo);
		return "viewHearResult";
	}
	
	public CaseSourceApprove getAppr() {
		return appr;
	}
	public void setAppr(CaseSourceApprove appr) {
		this.appr = appr;
	}
	public CaseSourceDrawApprove getDrawAppr() {
		return drawAppr;
	}
	public void setDrawAppr(CaseSourceDrawApprove drawAppr) {
		this.drawAppr = drawAppr;
	}

}

